<template>
  <div>
    <!-- 顶部布局 -->
    <div class="user-info">
      <van-image class="my-image" round fit="cover" :src="userInfo.photo" />
      <h2 class="name">
        {{ userInfo.name }} <br />
        <van-tag type="primary" color="#fff" text-color="#3296fa">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <!-- 列表 -->
    <van-row>
      <van-col span="8">
        <!-- <van-goods-action-icon
          color="#77aaff"
          icon="newspaper-o"
          text="我的作品"
          dot
        /> -->
        <van-icon color="#77aaff" name="newspaper-o" /><span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon color="#ff0000" name="star-o" /><span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon color="#ffaa00" name="tosend" /><span>我的作品</span>
      </van-col>
    </van-row>
    <!-- 底部 -->
    <div class="bottom">
      <van-cell-group>
        <van-cell title="编辑资料" icon="edit" is-link to="/edit" />
        <van-cell title="小智同学" icon="chat-o" is-link to="/student" />
        <van-cell title="系统设置" icon="setting-o" is-link />
        <van-cell title="退出登录" @click="loginOut" icon="warning-o" is-link />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
// import { getUserInfo } from '../../api/user'
// 导入辅助计算机自动计算属性
import { mapState } from 'vuex'
import { removeToken } from '../../utils/token'
export default {
  name: 'my',
  data () {
    return {
      // userInfo: {}
    }
  },
  computed: mapState(['userInfo']),
  // computed: {
  //   // 简化代码
  //   userInfo () {
  //     return this.$store.state.userInfo
  //   }
  // },
  // created () {
  //   getUserInfo().then(res => {
  //     // console.log(res)
  //     this.userInfo = res.data.data
  //   })
  // },
  methods: {
    loginOut () {
      this.$dialog
        .confirm({
          title: '确定退出吗？？？？',
          message: '再考虑考虑嘛'
        })
        .then(() => {
          // console.log('then')
          // 删除token
          removeToken()
          // 删除userInfo
          // this.userInfo = {}
          this.$store.commit('getUserInfo', {})
          // 返回首页
          this.$router.push({ path: '/home' })
        })
        .catch(() => {
          // on cancel
          console.log('cath')
        })
    }
  }
}
</script>

<style lang="less">
.user-info {
  height: 100px;
  background-color: #3296fa;
  display: flex;
  padding-left: 18px;
  justify-content: flex-start;
  align-items: center;
  .my-image {
    width: 60px;
    height: 60px;
    margin-right: 10px;
  }
  .name {
    color: white;
    font-size: 15px;
    font-weight: normal;
  }
}
.van-row {
  padding: 20px 0;
  .van-col {
    text-align: center;
    font-size: 12px;
    .van-icon {
      font-size: 25px;
    }
    span {
      display: block;
    }
  }
}
</style>
